﻿<%@ Page Language="C#" MasterPageFile="~/MasterPages/AdminDefault.Master" AutoEventWireup="true"
  CodeBehind="PhotoList.aspx.cs" Inherits="NguyenHoa.Web.Admin.PhotoList" Title="" %>

<%@ Register Assembly="DevExpress.Web.v9.1, Version=9.1.4.0, Culture=neutral, PublicKeyToken=5377c8e3b72b4073"
  Namespace="DevExpress.Web.ASPxPanel" TagPrefix="dxp" %>
<%@ Register Assembly="DevExpress.Web.ASPxEditors.v9.1, Version=9.1.4.0, Culture=neutral, PublicKeyToken=5377c8e3b72b4073"
  Namespace="DevExpress.Web.ASPxEditors" TagPrefix="dxe" %>
<%@ Register Assembly="DevExpress.Web.v9.1, Version=9.1.4.0, Culture=neutral, PublicKeyToken=5377c8e3b72b4073"
  Namespace="DevExpress.Web.ASPxPopupControl" TagPrefix="dxpc" %>
<%@ Register Assembly="DevExpress.Web.v9.1, Version=9.1.4.0, Culture=neutral, PublicKeyToken=5377c8e3b72b4073"
  Namespace="DevExpress.Web.ASPxDataView" TagPrefix="dxdv" %>
<%@ Register Src="../Controls/MultiUpload.ascx" TagName="MultiUpload" TagPrefix="uc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
  <div style="float: left;">
    <dxe:ASPxCheckBox ID="ckbAll" ClientInstanceName="ckbAll" runat="server" Text="<%$Resources:Strings, SelectAllItem %>"
      Cursor="pointer">
      <ClientSideEvents CheckedChanged="function(s,e){onCheckAll();e.processOnServer=false;}" />
    </dxe:ASPxCheckBox>
  </div>
  <div style="float: right; padding-top: 5px; font-style: italic; font-size: 11px;"
    class="CommonFont">
    <asp:Label ID="lblNote" runat="server" Text="<%$Resources:Strings,ImgSizeBanner %>"></asp:Label>
  </div>
  <div style="clear: both; padding-top: 20px;">
    <dxdv:ASPxDataView ID="dvList" ClientInstanceName="dvList" runat="server" ColumnCount="5"
      OnCustomCallback="dvList_CustomCallback" OnCustomJSProperties="dvList_CustomJSProperties"
      ItemSpacing="3px" PagerPanelSpacing="0px" OnDataBound="dvList_DataBound" Width="100%"
      BackColor="#ECF6FD">
      <ItemStyle Height="122px" Width="122px" BackColor="#ECF6FD">
        <Paddings Padding="0px" />
      </ItemStyle>
      <ItemTemplate>
        <div align="center" style="width: 122px; height: 122px;">
          <img alt="" src='<%#Eval("Path") %>' width="120px" height="120px" align="middle"
            style="padding: 2px;" />
        </div>
        <div style="width: 122px; padding-top: 8px;" align="center">
          <input id="item_checkbox" type="checkbox" runat="server" style="cursor: pointer;" />
        </div>
      </ItemTemplate>
      <ContentStyle ForeColor="#CC3300">
        <Paddings PaddingLeft="10px" PaddingRight="10px" />
      </ContentStyle>
      <ClientSideEvents EndCallback="function(s,e){ondvList_EndCallback(s,e);}" BeginCallback="function(s,e){ondvList_BeginCallback(s,e);}" />
      <Paddings Padding="0px" />
      <PagerSettings Position="Bottom">
        <AllButton>
          <Image Height="18px" Width="24px" />
        </AllButton>
        <FirstPageButton>
          <Image Height="18px" Width="22px" />
        </FirstPageButton>
        <LastPageButton>
          <Image Height="18px" Width="22px" />
        </LastPageButton>
        <NextPageButton>
          <Image Height="18px" Width="20px" />
        </NextPageButton>
        <PrevPageButton>
          <Image Height="18px" Width="20px" />
        </PrevPageButton>
        <Summary Text="<%$Resources:Strings, PagerText %>" />
      </PagerSettings>
    </dxdv:ASPxDataView>
  </div>
  <div style="float: left; padding-top: 10px;">
    <dxe:ASPxButton ID="btnAdd" runat="server" Text="<%$ Resources:Strings, Add %>" AutoPostBack="False">
      <ClientSideEvents Click="function(s,e){pcUpload.Show();}" />
    </dxe:ASPxButton>
  </div>
  <div style="float: left; padding-left: 3px; padding-top: 10px;">
    <dxe:ASPxButton ID="btnDelete" runat="server" Text="<%$ Resources:Strings, Delete %>"
      AutoPostBack="False">
      <ClientSideEvents Click="function(s,e){onDelete();}" />
    </dxe:ASPxButton>
  </div>
  <div style="float: left; padding-left: 3px; padding-top: 10px;">
    <dxe:ASPxButton ID="btnBackTo" runat="server" Text="<%$ Resources:Strings, BackTo %>"
      AutoPostBack="False">
      <ClientSideEvents Click="function(s,e){onBack();}" />
    </dxe:ASPxButton>
  </div>
  <div style="clear: both;">
    <dxpc:ASPxPopupControl ID="pcUpload" ClientInstanceName="pcUpload" runat="server"
      PopupHorizontalAlign="WindowCenter" PopupVerticalAlign="WindowCenter" Modal="True"
      HeaderText="<%$ Resources:Strings, Upload %>" AllowDragging="True" AllowResize="True"
      AutoUpdatePosition="True" PopupAction="None" ShowPageScrollbarWhenModal="True"
      CloseAction="CloseButton">
      <SizeGripImage Height="12px" Width="12px" />
      <ContentCollection>
        <dxpc:PopupControlContentControl>
          <dxp:ASPxPanel ID="ASPxPanel1" runat="server" Width="100%">
            <PanelCollection>
              <dxp:PanelContent>
                <div>
                  <uc1:MultiUpload ID="MultiUpload1" runat="server" />
                </div>
              </dxp:PanelContent>
            </PanelCollection>
          </dxp:ASPxPanel>
        </dxpc:PopupControlContentControl>
      </ContentCollection>
      <CloseButtonImage Height="18px" Width="18px" />
    </dxpc:ASPxPopupControl>
  </div>
  <div>
    <asp:HiddenField ID="hfSelectedList" runat="server" />
    <asp:HiddenField ID="hfCheckBoxList" runat="server" />
    <asp:HiddenField ID="hfAllIdList" runat="server" />
    <asp:HiddenField ID="hfBackTo" runat="server" />
  </div>

  <script type="text/javascript" language="javascript">
    function ondvList_BeginCallback(s, e) {
      var ids = document.getElementById('<%=hfCheckBoxList.ClientID %>').value.split(',');
      for (var i = 0; i < ids.length; i++) {
        if (ids[i] == '')
          continue;
        var checkbox = document.getElementById(ids[i]);
        if (checkbox != null) {
          checkbox.checked = false;
        }
      }
      document.getElementById('<%=hfSelectedList.ClientID %>').value = '';
    }

    function ondvList_EndCallback(s, e) {
      document.getElementById('<%=hfSelectedList.ClientID %>').value = '';
      var error = dvList.cpInnerError;
      if (error != '') {
        if (error.indexOf('SaveOK') >= 0 || error.indexOf('DeleteOK') >= 0) {
          var para = error.split('|');
          document.getElementById('<%=hfCheckBoxList.ClientID %>').value = para[1];
          document.getElementById('<%=hfAllIdList.ClientID %>').value = para[2];
          if (error.indexOf('SaveOK') >= 0)
            alertSuccess();
        }
        else
          alertMessage(error);
      }
      ckbAll.SetChecked(false);
    }

    function onBack() {
      var link = document.getElementById('<%=hfBackTo.ClientID %>').value;
      window.location.href = link;
    }

    function addCheckBoxId(s) {
      var id = s.id;
    }

    function onSelect(id, checked) {
      if (id == '')
        return;
      var oldSelected = document.getElementById('<%=hfSelectedList.ClientID %>').value.split(',');
      var newSelected = '';
      var isNew = true;
      for (var i = 0; i < oldSelected.length; i++) {
        if (oldSelected[i] == '')
          continue;
        if (oldSelected[i] == id) {
          isNew = false;
          if (!checked)
            continue;
        }
        newSelected += oldSelected[i] + ',';
      }
      if (isNew && checked)
        newSelected += id + ',';
      if (!checked)
        ckbAll.SetChecked(false);
      document.getElementById('<%=hfSelectedList.ClientID %>').value = newSelected;
    }

    function onDelete() {
      var deletedList = document.getElementById('<%=hfSelectedList.ClientID %>').value;
      if (confirm('<%=(string)GetGlobalResourceObject("Messages", "ERR0006") %>'))
        dvList.PerformCallback('Delete|' + deletedList);
    }

    function onCheckAll() {
      var ckbList = document.getElementById('<%=hfCheckBoxList.ClientID %>').value.split(',');
      var checked = ckbAll.GetChecked();
      for (var i = 0; i < ckbList.length; i++) {
        if (ckbList[i] == '')
          continue;
        var ckb = document.getElementById(ckbList[i]);
        if (ckb != null) {
          ckb.checked = checked;
        }
      }
      if (checked) {
        var idList = document.getElementById('<%=hfAllIdList.ClientID %>').value
        document.getElementById('<%=hfSelectedList.ClientID %>').value = idList;
      }
      else
        document.getElementById('<%=hfSelectedList.ClientID %>').value = '';
    }

    function UploadComplete() {
      pcUpload.Hide();
      dvList.PerformCallback('Save|');
    }
  </script>

</asp:Content>
